package com.wh1200.mybatis.xmlless.model

import com.wh1200.mybatis.xmlless.enums.JoinType
import net.sf.jsqlparser.expression.Expression

/**
 * Created by 吴昊 on 2018/12/17.
 */
class PropertyJoinInfo(
    joinTableInfo: XmllessTableInfo?,
    val propertyColumn: ColumnName,
    joinTable: TableName,
    type: JoinType,
    joinExpression: Expression,
    targetExpression: Expression,
    javaType: TypeInfo,
    val groupBy: String? = null
) : JoinInfo(
    joinTable, type, joinExpression, targetExpression, javaType,
    joinTableInfo
) {

  override fun selectFields(level: Int, prefix: String?, tablePrefix: String?): List<SelectColumn> {
    return when {
      groupBy != null -> listOf(SelectColumn(propertyColumn.fieldWrapper, null,
          propertyColumn.name, propertyColumn.alias))
      else            -> listOf(SelectColumn(propertyColumn.fieldWrapper, joinTable,
          propertyColumn.name, propertyColumn.alias))
    }
  }

}
